<?php
# Incluimos la configuracion
include ("includes/connection.php");

include ("includes/header.php");
include ("includes/iniciaSessio.php");
?>
	<body >
			<?php
			include ("includes/contentHeader.php");
			include ("./includes/menuMissatges.php");
			?>
		
			
		<!--contingut 1-->
		<section class="container">
			<!--fons gris-->
			<div class="hero-unit">
				<form method="post" action="#" >
	<?php
	$sql = "select * from usuari group by alias ASC";
	$result = mysql_query($sql, $conexion) or die(mysql_error());
						?>
						<p>Per:</p> <select name="per" id="select"  class="input-medium">
							<?php
							while ($row = mysql_fetch_array($result)) {
								echo "<option value=" . $row['alias'] . ">" . $row['alias'] . "</option>";
							}
							?>
						</select>
	<p>Assumpte:</p>
	<input type="text" name="assumpte" />
	<p>Missatge:</p>
	<textarea name="text"></textarea>
	<br />
	<br />
	<input type="submit" name="enviar" value="Enviar" class="enviarFrm btn btn-success"/>
</form>
<?php
if (isset($_POST['enviar'])) {
	if (isset($_POST['per']) && isset($_POST['assumpte']) && isset($_POST['text'])) {
		$data = date("j/m/Y, g:i a");
		$per = $_POST['per'];
		$de = $_SESSION['username'];
		$assumpte = $_POST['assumpte'];
		$text = $_POST['text'];
		$estat = 0;
		$sql = "insert into missatge (per ,de ,data ,assumpte ,text ,llegit) VALUES ('$per', '$de', '$data', '$assumpte', '$text', '$estat')";
		if (mysql_query($sql, $conexion)) {
			echo "	<script>
alert('Mensaje enviado correctamente');
</script>";
		} else {
			echo "	<script>
alert('Error al enviar mensaje');</script>";
		}
	}
}
?>
			</div>
			<!-- fi fons gris-->
		</section>
			<!-- fi contingut 1-->
		<!--contingut 2-->
		<section class="container">
			<div class="hero-unit"></div>
		</section>
		<!-- fi contingut 2-->
	<hr>
	<?php
	include ("includes/footer.php");
	?>
